<!DOCTYPE html>
<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>综合管理平台</title>
  <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body class="Login">
  <!--Login-开始-->

  <div class="Login_heand dk">
    <a href="#" class="Login_logo fl">
      <h3>欢迎进入源当当！</h3>
      <div class="clear"></div>
    </a>
  </div>

  <div class="Login_k">
    <div class="Login_T">
      密码登录
      <p></p>
    </div>
    <!--登录-开始-->
    <form class="Login_dl">
      <div class="Login_row">
        <input name="zhanghao" type="text" value="" class="Login_input Login_inp1" placeholder="用户名" id="userName" />
      </div>
      <div class="Login_row">
        <input name="password" type="password" value="" class="Login_input Login_inp2" placeholder="密码" id="pwd" />
      </div>
      <a href="#" class="Login_dla" id="localStorage">登录</a>

      <label class="Login_pitch fl">
        <input type="checkbox" name="checkbox01" class="fl" />
        <div class="fl">自动登录</div>
        <div class="clear"></div>
      </label>
      <div class="Login_wj fr">
        <a href="register.html">用户注册</a>
      </div>
      <div class="clear"></div>
    </form>
    <!--登录-结束-->
  </div>
  <!--Login-结束-->
  <script>
    document.getElementById('localStorage').onclick = function () {
      var userName = document.getElementById('userName').value
      var pwd = document.getElementById('pwd').value
      if (!localStorage.getItem('info')) {
        alert('您还没注册')
        location.replace('register.html')
        return
      }
      var info = JSON.parse(localStorage.getItem('info'))
      if (userName == info.userName && pwd == info.pwd) {
        if (sessionStorage.getItem('login')) {
          alert('您已登录，2秒后跳转到首页')
          setTimeout(() => {
            location.href = 'index.html'
          }, 2000)
        } else {
          sessionStorage.setItem("login", userName)
          location.href = "index.html"

        }
      } else {
        alert("用户名或密码错误，请先注册")
        location.replace("register.html")
      }
    }
  </script>
</body>

</html>